#include "ConcreteMediator.h"

namespace Mediator{
    ConcreteMediator::ConcreteMediator() {
        this->colleagues = new std::map<std::string, Colleague*>();
    }

    void ConcreteMediator::operation(std::string *who) {
        auto colleague = this->colleagues->find(*who);
        if(colleague == this->colleagues->end()){
            std::cout << "no " << who << "in concreteMediator" << std::endl;
        }else{
            colleague->second->receiveMsg();
        }
    }

    void ConcreteMediator::registe(Colleague *colleague) {
        if(this->colleagues == nullptr){
            throw new std::exception();
        }
        this->colleagues->insert(std::pair<std::string, Colleague*>(colleague->getName(), colleague));
        std::cout << "register " << colleague->getName() << " in concreteMediator" << std::endl;
        colleague->setMediator(this);
    }
}
